<html>
<head><meta charset="utf-8"><title>Wasm version of Rust Analyzer · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html">Wasm version of Rust Analyzer</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240943375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240943375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240943375">(Jun 01 2021 at 13:41)</a>:</h4>
<p>Hello,</p>
<p>I'm experimenting with the WASM version of Rust Analyzer: <a href="https://github.com/rust-analyzer/rust-analyzer-wasm">https://github.com/rust-analyzer/rust-analyzer-wasm</a></p>
<p>As far as I can see, it can only receive the content of a single file but not of a full crate. This is since it is only implementing ra_ap_ide::Analysis and not ra_ap_ide::AnalysisHost? If I want it to analyze a complete crate, resolving dependencies from a Cargo.toml file, I assume that I've to add AnalysisHost, create a Change and use AnalysisHost.apply_change, so that I can finally create a Analysis instance from AnaylsisHost for analysis of the current file? </p>
<p>Did someone ever try something like this? Any hints on some sample code? I'm an experienced Typescript dev, but relatively new to Rust. I appreciate any help!</p>
<p>Best,<br>
Achim</p>



<a name="240944206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240944206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240944206">(Jun 01 2021 at 13:48)</a>:</h4>
<p>I don't think it's about <code>AnalysisHost</code> vs. <code>Analysis</code>; you need an <code>AnalysisHost</code> to get an <code>Analysis</code>, <code>from_single_file</code> just creates one internally. The issue is getting a project model, since you can't run cargo. You could just look at what <code>from_single_file</code> does and add more files and even a more complicated <code>CrateGraph</code> if you want</p>



<a name="240944433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240944433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240944433">(Jun 01 2021 at 13:50)</a>:</h4>
<p>I see that the WASM demo actually recreates the analysis whenever the code changes; I don't think that's really the intended way to do it, not sure why it's doing that</p>



<a name="240944486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240944486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240944486">(Jun 01 2021 at 13:51)</a>:</h4>
<p>usually you have to hold on to the <code>AnalysisHost</code> and then apply changes to the files as you get them</p>



<a name="240944766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240944766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240944766">(Jun 01 2021 at 13:52)</a>:</h4>
<p>also, <a href="https://rust-analyzer.github.io/rust-analyzer/src/ide/lib.rs.html#201-227">Analysis::from_single_file</a> has a doc comment that isn't a doc comment...</p>



<a name="240944908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240944908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240944908">(Jun 01 2021 at 13:53)</a>:</h4>
<p>The comment on <code>impl Analysis</code> can also be turned into a doc comment.</p>



<a name="240945032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240945032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240945032">(Jun 01 2021 at 13:54)</a>:</h4>
<p>that one is more a notice for people changing the code though, so it kind of makes sense to not make it a doc comment</p>



<a name="240945104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/240945104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#240945104">(Jun 01 2021 at 13:55)</a>:</h4>
<p>Yes, I was also thinking that it is a very preliminary version!</p>
<p>But investigating the from_single_file method in the Rust Analyzer sourcecode is already a big help. That's the sample creation of an AnalysisHost from some file, that I was searching for. Will try to understand and use it. Thanks!</p>



<a name="241128439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241128439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241128439">(Jun 02 2021 at 10:04)</a>:</h4>
<p>Is there any sample code available which converts a Cargo.toml file into a CrateGraph that I can pass to AnalysisHost. </p>
<p>I found this guide: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/">https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/</a>, but I think it's outdated.</p>



<a name="241128708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241128708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241128708">(Jun 02 2021 at 10:07)</a>:</h4>
<p>you need Cargo to do that. Then it's basically <a href="https://github.com/rust-analyzer/rust-analyzer/blob/dbdfeeeff91b5e42d8687df09dda1d29f99b34f8/crates/rust-analyzer/src/cli/load_cargo.rs#L35-L128">this</a></p>



<a name="241128801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241128801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241128801">(Jun 02 2021 at 10:08)</a>:</h4>
<p>but you're not going to be able to do it in wasm, unless you compile Cargo to wasm (which may be possible? I don't know how well-abstracted the I/O parts are in Cargo)</p>



<a name="241128885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241128885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241128885">(Jun 02 2021 at 10:09)</a>:</h4>
<p>The I/O parts are not abstracted at all. It would probably compile for wasm32-wasi though.</p>



<a name="241130092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241130092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241130092">(Jun 02 2021 at 10:23)</a>:</h4>
<p>But if most of the files I want to edit online are using the same dependencies, then I could create the CrateGraph once and parse it as a JSON to the Wasm version of Rust Analyzer?</p>



<a name="241131093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241131093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241131093">(Jun 02 2021 at 10:33)</a>:</h4>
<p>that should be possible. Note that you still need to somehow bundle and provide the code for all those dependencies</p>



<a name="241131106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241131106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241131106">(Jun 02 2021 at 10:33)</a>:</h4>
<p>including the standard library</p>



<a name="241131163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241131163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241131163">(Jun 02 2021 at 10:34)</a>:</h4>
<p>or I guess you could also retrieve it</p>



<a name="241383363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241383363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241383363">(Jun 03 2021 at 12:30)</a>:</h4>
<p>There seems to be even an implementation of a .json format for CrateGraphs: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/dbdfeeeff91b5e42d8687df09dda1d29f99b34f8/crates/project_model/src/project_json.rs">https://github.com/rust-analyzer/rust-analyzer/blob/dbdfeeeff91b5e42d8687df09dda1d29f99b34f8/crates/project_model/src/project_json.rs</a>. But within the code I can only find functions which are converting json to CrateGraphs. Do you have any advice of how I can get such a rust-project.json file from either a crate.graph or Cargo.toml file / cargo metadata output?</p>



<a name="241383531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241383531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241383531">(Jun 03 2021 at 12:31)</a>:</h4>
<p>no, they're intended to be written by hand or other build systems</p>



<a name="241383717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241383717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241383717">(Jun 03 2021 at 12:33)</a>:</h4>
<p>But it should be possible to write a script which converts cargo metadata to a rust-project.json file?</p>



<a name="241383835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241383835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241383835">(Jun 03 2021 at 12:34)</a>:</h4>
<p>yes, that should be possible. It could even be useful as a <code>rust-analyzer</code> command</p>



<a name="241383924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/241383924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#241383924">(Jun 03 2021 at 12:35)</a>:</h4>
<p>which would probably be pretty straightforward, since it could just get the <code>CrateGraph</code> and then convert back to the project json format</p>



<a name="242306644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242306644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242306644">(Jun 11 2021 at 06:43)</a>:</h4>
<p>I implemented a serialization and deserialization of the CrateGraph as well as of the Change object in my own version of RustAnalyzer. I will see if I can provide a PR which implements a CLI command for creating a rust-project.json file! Many thanks so far!</p>



<a name="242306736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242306736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242306736">(Jun 11 2021 at 06:45)</a>:</h4>
<p>I'm currently running into problems when I try to compile any version of rust-analyzer to WebAssembly up from  0.0.48.</p>
<p>Here is the compiler error after changing the rust version to 0.0.48. in Cargo.toml of the wasm version of rust-analyzer:</p>
<p>error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0<br>
   --&gt; /home/achim/.cargo/registry/src/github.com-1ecc6299db9ec823/ra_ap_stdx-0.0.48/src/lib.rs:182:1<br>
    |<br>
182 | pub struct JodChild(pub process::Child);<br>
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0</p>
<p>error: aborting due to previous error</p>
<p>For more information about this error, try <code>rustc --explain E0690</code>.<br>
error: could not compile <code>ra_ap_stdx</code></p>



<a name="242306760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242306760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242306760">(Jun 11 2021 at 06:45)</a>:</h4>
<p>Any ideas what could fix this?</p>



<a name="242313772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242313772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Mcnab <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242313772">(Jun 11 2021 at 08:16)</a>:</h4>
<p>Ah, so that's because wasm can't have child processes<br>
The easiest way would be to make it be not repr(transparent) on wasm and panic before trying to transmute into it</p>



<a name="242316120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316120">(Jun 11 2021 at 08:41)</a>:</h4>
<p>it kind of seems that if we're trying to create child processes in wasm, it's already too late? i.e. maybe the type just shouldn't exist in wasm?</p>



<a name="242316199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316199">(Jun 11 2021 at 08:42)</a>:</h4>
<p>but maybe that goes against the normal approach</p>



<a name="242316426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316426">(Jun 11 2021 at 08:44)</a>:</h4>
<p>it's used by flycheck, which probably isn't in your dependency tree, and proc_macro_api, which... probably also shouldn't be</p>



<a name="242316617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316617">(Jun 11 2021 at 08:46)</a>:</h4>
<p>I wonder if we should have a WASM build in CI</p>



<a name="242316627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316627">(Jun 11 2021 at 08:47)</a>:</h4>
<p>of the crates that are supposed to work in WASM</p>



<a name="242316661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316661">(Jun 11 2021 at 08:47)</a>:</h4>
<p>i.e. everything behind <code>ide</code></p>



<a name="242316867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316867">(Jun 11 2021 at 08:49)</a>:</h4>
<p>I guess the other question is why <code>JodChild</code> needs to be <code>repr(transparent)</code> at all <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="242316995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242316995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242316995">(Jun 11 2021 at 08:51)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> why can't <code>JodChild::into_inner</code> not simply return <code>self.0</code>?</p>



<a name="242317347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242317347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242317347">(Jun 11 2021 at 08:55)</a>:</h4>
<p>oh, because it implements Drop</p>



<a name="242321390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242321390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242321390">(Jun 11 2021 at 09:35)</a>:</h4>
<p>It could contain an <code>Option&lt;Child&gt;</code> and do nothing in the <code>Drop</code> impl if it is <code>None</code>.</p>



<a name="242321810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242321810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242321810">(Jun 11 2021 at 09:39)</a>:</h4>
<p>It'd be fine to make repr transparent conditional, and just panic in the <code>into</code> on wasm</p>



<a name="242325659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242325659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242325659">(Jun 11 2021 at 10:19)</a>:</h4>
<p>While trying to compile the most recent version of rust-analyzer to wasm, I'm facing even more errors:</p>



<a name="242325669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242325669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242325669">(Jun 11 2021 at 10:19)</a>:</h4>
<p>error[E0433]: failed to resolve: use of undeclared crate or module <code>imp</code><br>
  --&gt; /home/achim/.cargo/registry/src/github.com-1ecc6299db9ec823/ra_ap_stdx-0.0.59/src/process.rs:25:9<br>
   |<br>
25 |         imp::read2(out, err, &amp;mut |is_out, data, eof| {<br>
   |         ^^^ use of undeclared crate or module <code>imp</code></p>
<p>error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0<br>
   --&gt; /home/achim/.cargo/registry/src/github.com-1ecc6299db9ec823/ra_ap_stdx-0.0.59/src/lib.rs:114:1<br>
    |<br>
114 | pub struct JodChild(pub std::process::Child);<br>
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0</p>
<p>error[E0658]: use of unstable library feature 'partition_point': new API<br>
  --&gt; /home/achim/.cargo/registry/src/github.com-1ecc6299db9ec823/ra_ap_stdx-0.0.59/src/lib.rs:95:23<br>
   |<br>
95 |     let start = slice.partition_point(|it| key(it) == Ordering::Less);<br>
   |                       ^^^^^^^^^^^^^^^<br>
   |<br>
   = note: see issue <a href="https://github.com/rust-lang/rust/issues/73831">#73831</a> &lt;<a href="https://github.com/rust-lang/rust/issues/73831">https://github.com/rust-lang/rust/issues/73831</a>&gt; for more information<br>
   = help: add <code>#![feature(partition_point)]</code> to the crate attributes to enable</p>
<p>error[E0658]: use of unstable library feature 'partition_point': new API<br>
  --&gt; /home/achim/.cargo/registry/src/github.com-1ecc6299db9ec823/ra_ap_stdx-0.0.59/src/lib.rs:96:30<br>
   |<br>
96 |     let len = slice[start..].partition_point(|it| key(it) == Ordering::Equal);<br>
   |                              ^^^^^^^^^^^^^^^<br>
   |<br>
   = note: see issue <a href="https://github.com/rust-lang/rust/issues/73831">#73831</a> &lt;<a href="https://github.com/rust-lang/rust/issues/73831">https://github.com/rust-lang/rust/issues/73831</a>&gt; for more information<br>
   = help: add <code>#![feature(partition_point)]</code> to the crate attributes to enable</p>
<p>error: aborting due to 4 previous errors</p>
<p>Some errors have detailed explanations: E0433, E0658, E0690.<br>
For more information about an error, try <code>rustc --explain E0433</code>.<br>
error: could not compile <code>ra_ap_stdx</code></p>



<a name="242325944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242325944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242325944">(Jun 11 2021 at 10:21)</a>:</h4>
<p>Two of those are due to you not running the latest stable toolchain, RA usually only builds on the latest rust version</p>



<a name="242327120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242327120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242327120">(Jun 11 2021 at 10:32)</a>:</h4>
<p>Ah, thanks! The toolchain is set to nightly-2021-02-11<br>
 in the rust-toolchain file in the wasm GitHub Repo. After setting it to stable, two errors remain:</p>
<p>error[E0433]: failed to resolve: use of undeclared crate or module <code>imp</code><br>
  --&gt; /home/achim/.cargo/registry/src/github.com-1ecc6299db9ec823/ra_ap_stdx-0.0.59/src/process.rs:25:9<br>
   |<br>
25 |         imp::read2(out, err, &amp;mut |is_out, data, eof| {<br>
   |         ^^^ use of undeclared crate or module <code>imp</code></p>
<p>error[E0690]: transparent struct needs exactly one non-zero-sized field, but has 0<br>
   --&gt; /home/achim/.cargo/registry/src/github.com-1ecc6299db9ec823/ra_ap_stdx-0.0.59/src/lib.rs:114:1<br>
    |<br>
114 | pub struct JodChild(pub std::process::Child);<br>
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0</p>



<a name="242327204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242327204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242327204">(Jun 11 2021 at 10:33)</a>:</h4>
<p>I'm guessing that E0433 is due to trying some fs access, which is not available is wasm?</p>



<a name="242327412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242327412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242327412">(Jun 11 2021 at 10:35)</a>:</h4>
<p>it's because our <code>process.rs</code> only has implementations for unix and windows</p>



<a name="242327446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242327446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242327446">(Jun 11 2021 at 10:35)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/stdx/src/process.rs">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/stdx/src/process.rs</a></p>



<a name="242334910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242334910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242334910">(Jun 11 2021 at 12:01)</a>:</h4>
<p>Okay, I see the point. I think I can probably fix that JodChild issue. Is it possible to implement a wasm version for <a href="http://process.rs">process.rs</a>? Problably by preceding imp with #[cfg(target_arch = "wasm32")]? Sorry for all the noob questions, really very new to rust!</p>



<a name="242335167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242335167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242335167">(Jun 11 2021 at 12:04)</a>:</h4>
<p>yeah, presumably the WASM implementation would just return an error unconditionally (since the <code>Command</code> API also doesn't work there)</p>



<a name="242335384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/242335384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#242335384">(Jun 11 2021 at 12:06)</a>:</h4>
<p>I was assuming that it shouIdn't get called! I tried to add a dummy implementation. Compilation passes beyond this point! Now new errors are showing up :/ </p>
<p>Compiling ide v0.0.0 (/home/achim/Projects/rust-analyzer/crates/ide)<br>
error[E0277]: the trait bound <code>std::string::String: From&lt;Url&gt;</code> is not satisfied<br>
   --&gt; /home/achim/Projects/rust-analyzer/crates/ide/src/doc_links.rs:289:24<br>
    |<br>
289 |         .map(|url| url.into())<br>
    |                        ^^^^ the trait <code>From&lt;Url&gt;</code> is not implemented for <code>std::string::String</code><br>
    |<br>
    = help: the following implementations were found:<br>
              &lt;std::string::String as From&lt;&amp;'a js_sys::JsString&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;mut str&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;std::string::String&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;str&gt;&gt;<br>
            and 10 others<br>
    = note: required because of the requirements on the impl of <code>Into&lt;std::string::String&gt;</code> for <code>Url</code></p>
<p>error[E0277]: the trait bound <code>std::string::String: From&lt;Url&gt;</code> is not satisfied<br>
   --&gt; /home/achim/Projects/rust-analyzer/crates/ide/src/doc_links.rs:328:19<br>
    |<br>
328 |     Some((new_url.into(), strip_prefixes_suffixes(title).to_string()))<br>
    |                   ^^^^ the trait <code>From&lt;Url&gt;</code> is not implemented for <code>std::string::String</code><br>
    |<br>
    = help: the following implementations were found:<br>
              &lt;std::string::String as From&lt;&amp;'a js_sys::JsString&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;mut str&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;std::string::String&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;str&gt;&gt;<br>
            and 10 others<br>
    = note: required because of the requirements on the impl of <code>Into&lt;std::string::String&gt;</code> for <code>Url</code></p>
<p>error[E0277]: the trait bound <code>std::string::String: From&lt;Url&gt;</code> is not satisfied<br>
   --&gt; /home/achim/Projects/rust-analyzer/crates/ide/src/doc_links.rs:348:24<br>
    |<br>
348 |         .map(|url| url.into())<br>
    |                        ^^^^ the trait <code>From&lt;Url&gt;</code> is not implemented for <code>std::string::String</code><br>
    |<br>
    = help: the following implementations were found:<br>
              &lt;std::string::String as From&lt;&amp;'a js_sys::JsString&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;mut str&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;std::string::String&gt;&gt;<br>
              &lt;std::string::String as From&lt;&amp;str&gt;&gt;<br>
            and 10 others<br>
    = note: required because of the requirements on the impl of <code>Into&lt;std::string::String&gt;</code> for <code>Url</code></p>
<p>error: aborting due to 3 previous errors</p>



<a name="243366599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243366599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243366599">(Jun 21 2021 at 11:06)</a>:</h4>
<p>Just in case that someone is interested: I managed to serialize/deserialize a Change object. Now my WASM Version of rust analyzer is loading the dependencies for ink Smart Contracts (<a href="https://github.com/paritytech/ink">https://github.com/paritytech/ink</a>), allowing the online editing of a Smart Contract file.</p>
<p>You can test the current version here: </p>
<p><a href="https://friendly-ramanujan-7bfd78.netlify.app/">https://friendly-ramanujan-7bfd78.netlify.app/</a> </p>
<p>Please note that rust analyzer only becomes available after being loaded, which takes up to 20 seconds.</p>



<a name="243366686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243366686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243366686">(Jun 21 2021 at 11:07)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> <span class="user-mention" data-user-id="133169">@matklad</span> Do you have any estimate how long it might take until the current version of rust analyzer becomes compilable to wasm again? I'm currently using version 0.45.</p>



<a name="243366807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243366807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243366807">(Jun 21 2021 at 11:09)</a>:</h4>
<p>In "CPU time", I'd estimate that as half-a-day worth of work. In "wall-clock time", well, when someone invests this half a day!</p>



<a name="243367105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243367105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243367105">(Jun 21 2021 at 11:12)</a>:</h4>
<p>I can do my best trying to support. It's just that my background is being a TypeScript developer so far, this is the first time for me working with rust. Will probably find support from some colleagues within my company too ;)</p>



<a name="243380287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243380287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243380287">(Jun 21 2021 at 13:19)</a>:</h4>
<p>I am getting the following error:</p>
<blockquote>
<p>DataCloneError: Worker.postMessage: The WebAssembly.Memory object cannot be serialized. The Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy HTTP headers can be used to enable this.</p>
</blockquote>



<a name="243380322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243380322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243380322">(Jun 21 2021 at 13:19)</a>:</h4>
<p>This is using firefox.</p>



<a name="243381869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243381869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243381869">(Jun 21 2021 at 13:30)</a>:</h4>
<p>Ah yes! Currently it is only working for Chrome. It's just a very early WIP...</p>



<a name="243382431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243382431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243382431">(Jun 21 2021 at 13:34)</a>:</h4>
<p>it's working for me, very cool <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="243570658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/243570658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#243570658">(Jun 22 2021 at 19:54)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/pull/9381">https://github.com/rust-analyzer/rust-analyzer/pull/9381</a></p>



<a name="244275738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244275738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244275738">(Jun 29 2021 at 12:58)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> Thanks a lot for fixing the compilation to WASM! Unfortunately, wasm-pack build still fails to build a valid .wasm file:</p>
<p><code>[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling wasm_demo v0.1.0 (/home/achim/Projects/wasm/rust-analyzer-react-typescript)
error: linking with </code>rust-lld` failed: exit status: 1</p>
<p>...</p>
<p>= note: rust-lld: error: mutable global exported but 'mutable-globals' feature not present in inputs: <code>__tls_base</code>. Use --no-check-features to suppress.<br>
          rust-lld: error: mutable global exported but 'mutable-globals' feature not present in inputs: <code>__tls_size</code>. Use --no-check-features to suppress.<br>
          rust-lld: error: mutable global exported but 'mutable-globals' feature not present in inputs: <code>__tls_align</code>. Use --no-check-features to suppress.</p>
<p>`</p>
<p>Any suggestions what I could do to fix this?</p>



<a name="244276533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244276533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244276533">(Jun 29 2021 at 13:03)</a>:</h4>
<p>What is the exact wasm-pack command you tried? Did you enable any target-features?</p>



<a name="244276689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244276689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244276689">(Jun 29 2021 at 13:04)</a>:</h4>
<p>looks like <a href="https://github.com/rustwasm/wasm-bindgen/issues/2487">https://github.com/rustwasm/wasm-bindgen/issues/2487</a> ?</p>



<a name="244276777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244276777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244276777">(Jun 29 2021 at 13:05)</a>:</h4>
<p>so updating wasm-bindgen may help?</p>



<a name="244276973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244276973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244276973">(Jun 29 2021 at 13:06)</a>:</h4>
<p>That only applies to when using wasm shared memory for multi threading and the change in that PR is in the command the user uses, not what wasm-bindgen uses.</p>



<a name="244278614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244278614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244278614">(Jun 29 2021 at 13:19)</a>:</h4>
<p>I use <code>wasm-pack build --target web </code> for compiling. I tried a variety of wasm-bindgen versions and toolchains, it fails with  wasm-bindgen = "0.2.74" too...</p>



<a name="244278783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244278783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244278783">(Jun 29 2021 at 13:20)</a>:</h4>
<p>wasm-bingen-rayon requires to set some addiaitonal parameters, like nightly toolchain and some extra flags in .cargo/config:</p>
<p>`[target.wasm32-unknown-unknown]<br>
rustflags = ["-C", "target-feature=+atomics,+bulk-memory"]</p>
<p>[unstable]<br>
build-std = ["panic_abort", "std"]`</p>
<p>See: <a href="https://github.com/GoogleChromeLabs/wasm-bindgen-rayon">https://github.com/GoogleChromeLabs/wasm-bindgen-rayon</a></p>



<a name="244278869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244278869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244278869">(Jun 29 2021 at 13:21)</a>:</h4>
<p>You have to add <code>+mutable-globals</code>: <a href="https://github.com/rustwasm/wasm-bindgen/pull/2488/files#diff-b4df63c506d6bfc7e14d93aeb1fe129c3ad10b3f6b1df7a1f4cc6ebff862d059R15">https://github.com/rustwasm/wasm-bindgen/pull/2488/files#diff-b4df63c506d6bfc7e14d93aeb1fe129c3ad10b3f6b1df7a1f4cc6ebff862d059R15</a></p>



<a name="244281430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244281430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244281430">(Jun 29 2021 at 13:37)</a>:</h4>
<p>I tried this flag before, since the error message also suggested it. But I either had a typo or something else was wrongly configured. However, it compiles now :) Thanks a lot!</p>



<a name="244409240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244409240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244409240">(Jun 30 2021 at 11:33)</a>:</h4>
<p>I'm currently using my own modified version of rust analyzer in which I implemented the serialization and deserialization of the <code>Change</code> object, which is send to the <code>AnalysisHost</code>. I also added a CLI command to generate a .json file for a rust project. This way I'm able to load the dependencies for the rust analyzer into the version which I compiled to WASM. Would this feature be of general interest? Should I create a PR for it? Or would there be a better way to load the dependencies of a rust project into the WASM version?</p>



<a name="244410807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/244410807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#244410807">(Jun 30 2021 at 11:52)</a>:</h4>
<p>hmm, maybe it'd be best to make a draft PR so we have something concrete to talk about</p>



<a name="246060667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/246060667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#246060667">(Jul 15 2021 at 07:32)</a>:</h4>
<p>Hey ;)<br>
I would still like to do this PR. </p>
<p>However, I was serializing/deserializing the <code>Change</code> object without the proc-macros. I was planning to add this before I publish a PR.</p>
<p>But I realized that the proc-macros are handled by ProcMacroSrv which is not used by the IDE crate? So I guess they won't be available in a wasm version of rust-analyzer, anyway? Or at least not until someone implements a wasm version of ProcMacroSrv? Since it is using threads it probably wouldn't compile to wasm?</p>



<a name="246060823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/246060823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#246060823">(Jul 15 2021 at 07:35)</a>:</h4>
<p>Do you have a compiler? You'd need to compile the proc macros before running them anyway.</p>



<a name="246061871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/246061871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Achim Schneider <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#246061871">(Jul 15 2021 at 07:49)</a>:</h4>
<p>I don't have a compiler in WASM, unfortunately. But it might be possible to use pre-compiled proc-macros? Can you tell me where rust analyzer handles the compilation of proc macros?</p>



<a name="246069921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/246069921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#246069921">(Jul 15 2021 at 09:15)</a>:</h4>
<p>It is not possible to compile proc-macros for wasm. They are compiled by rustc as dylibs (invoked by <code>cargo check</code>). None of the wasm targets don't support dylibs yet.</p>



<a name="246076436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/246076436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#246076436">(Jul 15 2021 at 10:34)</a>:</h4>
<p>well, there's nothing in rust-analyzer that requires that to be the case. for the hir / ide crates, a proc macro is just a <code>dyn ProcMacroExpander</code>. it'd be possible to build in precompiled proc macros, for example. it wouldn't be trivial, though</p>



<a name="246076650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/246076650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#246076650">(Jul 15 2021 at 10:36)</a>:</h4>
<p>it might even be possible to precompile the proc macros to wasm using watt and load that</p>



<a name="246077111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Wasm%20version%20of%20Rust%20Analyzer/near/246077111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Wasm.20version.20of.20Rust.20Analyzer.html#246077111">(Jul 15 2021 at 10:42)</a>:</h4>
<p>nevertheless, I would recommend leaving that out of the PR for now <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>